package com.delayqueue.core.init;

import com.delayqueue.core.netty.handler.master.MasterConnectBootstrap;
import com.delayqueue.core.netty.handler.registry.RegistryConnectBootstrap;
import com.delayqueue.core.permanent.PermanentHandler;
import com.delayqueue.core.queue.QueueHandler;
import com.delayqueue.core.thread.ThreadHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class Init implements ApplicationRunner {

    @Autowired
    private QueueHandler queueHandler;

    @Autowired
    private ThreadHandler threadHandler;

    @Autowired
    private PermanentHandler permanentHandler;

    @Autowired
    private RegistryConnectBootstrap registryConnectBootstrap;

    @Autowired
    private MasterConnectBootstrap masterConnectBootstrap;

    @Override
    public void run(ApplicationArguments args) {
        log.info("系统初始化开始");
        threadHandler.init();
        permanentHandler.init();
        queueHandler.start();
        registryConnectBootstrap.connect();
        masterConnectBootstrap.connect();
        log.info("系统初始化完毕");
    }
}
